package com.luoran.system.xxljob;

import com.luoran.system.api.domain.SysUser;
import com.luoran.system.config.QQMailUtils;
import com.luoran.system.service.ISysUserService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import groovy.util.logging.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.security.auth.Subject;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class Xxljob {
    @Autowired
    ISysUserService iSysUserService;

    private static Set<SysUser> set;

    private static String fromEmail = "tencetmusician@vip.qq.com";
    private static String authCode = "teaekbfumgbdbcca";
    private static String toEmail = "";
    private static String subject = "亲爱的智慧车用户：";
    private static String messageBoday = "<h1>"+"</h1>";

    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("myJobHandler")
    public void demoJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, Hello World.");
        List<SysUser> list = iSysUserService.getUserList();
        for (SysUser sysUser : list) {
            try {
                QQMailUtils.sendEmail(fromEmail,authCode,sysUser.getEmail(),subject+sysUser.getUserName(),"<h1>您已成为智慧车平台"+sysUser.getRegistration_years()+"年用户,感谢您的支持与陪伴</h1>",true);
            }catch (MessagingException e){
                e.printStackTrace();
            }
        }
        System.out.println("定时任务执行成功");
    }
}
